
/*
	USE THIS CLASS IN THE FUTURE IF YOU WANT TO CHECK THE CONTROLS OF A FORM
	IT WILL COME IN HANDY FOR READING THE CIML FILE
*/


import org.w3c.dom.*;
import java.io.*;
import javax.xml.parsers.*;
import java.util.*;
import datolib.*;

public class Ciml {
	
/*
	public static GuiForm load(String filePath) {

		try {
 
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            
            File file = new File(filePath);
 
            if (!file.exists()) {
            	System.out.println("file not found");
            	return null;
            }
            
            Document ciml = db.parse(file);
            
            Element applicationElement = ciml.getDocumentElement();
            
            NodeList applicationForms = applicationElement.getElementsByTagName("form");
            
            GuiForm form = Ciml.loadForm(applicationForms.item(0)); //get the first one (there should only be one) 
          
            
 			return form;
           
        } catch (Exception e) {
        e.printStackTrace();
            return null;
        }
	}*/
	/*	
	private static GuiForm loadForm(Node formNode) {
		
	 
        NamedNodeMap attributes = formNode.getAttributes();	
            	
        String id = Ciml.getAttribute(attributes, "id");
        
        if (id == null || id == "") {
        	return null;
        }
        
        GuiForm form = new GuiForm(id);
            	
        NodeList controls = formNode.getChildNodes();
        
        loadControls(form, controls);
        
        return form;
	}
	
	private static void loadControls(GuiForm form, NodeList controls) {
		for (int i = 0; i < controls.getLength(); ++i) {
			
			Node controlNode = controls.item(i);	
		
			if (controlNode.getNodeType() == Node.ELEMENT_NODE) {
				
				Ciml.addControl(form, controlNode);
			
			}
					
		}
	}
	
	private static void addControl(GuiForm form, Node control) {
					
		String nodeName = control.getNodeName();
		
		NamedNodeMap attributes = control.getAttributes();
		
		String id = Ciml.getAttribute(attributes, "id");
		
		
			
		if (id == null) {
			return;
		}
	
			
		if (nodeName.equals("button")) {
			form.add(new GuiButton(id));
		} else if (nodeName.equals("textbox")) {
			form.add(new GuiTextbox(id));
		} else if (nodeName.equals("label")) {
			form.add(new GuiLabel(id));
		}
	
	}
	
	
	
	private static String getAttribute(NamedNodeMap attributes, String name) {
	
		for(int i = 0 ; i < attributes.getLength() ; i++) {
        
      		Attr attribute = (Attr)attributes.item(i);
      		
        	if (attribute.getName().equals(name)) {
        		return attribute.getValue();
        	}     
        	        	
      	}
      	return null;	
	}	*/
}
